#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> vp;
    for (int i = 0; i < n; i++)
    {
        int l, r;
        cin >> l >> r;
        vp.push_back({l, r});
    }
    sort(vp.begin(), vp.end(),
         [](pair<int, int> &a, pair<int, int> &b)
         { 
            if(a.first==b.first)
                return a.second < b.second;
            return a.first < b.first; });
    int cnt = 0;
    int nowl = -1, nowr = -1;
    for (int i = 0; i < n; i++)
    {
        int ll = vp[i].first, rr = vp[i].second;
        if (nowl == -1 && nowr == -1)
        {
            nowl = ll, nowr = rr;
        }
        else
        {
            if (ll <= nowr + 1)
            {
                nowr = max(nowr, rr);
            }
            else
            {
                cnt += (nowr - nowl + 1);
                nowl = ll, nowr = rr;
            }
        }
    }
    cnt += (nowr - nowl + 1);
    cout << cnt << endl;
    return 0;
}